package com.ly.weixmesg.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;

import java.io.IOException;

/**
 * @author LBG
 * @creat 2022-09-12-18:34
 */
@Configuration
@EnableScheduling
public class WQFweixinTask implements SchedulingConfigurer {
    @Override
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        scheduledTaskRegistrar.addTriggerTask(
                //1.添加任务内容(Runnable)
                () ->{
                    try {

                        Pusher.push();
                    }
                    catch (Exception e) {
                        e.printStackTrace();
                    }


                },triggerContext -> {


                    String cron = "";

                    //cron = "00 24 10 * * ?";
//                    0 25 15 * * ?   秒分时   指定每天15:25:00推送一次
                    //*/60 * * * * *  每60秒推送一次
                    //0 0/5 * * * ?   每5分钟推送一次
//                     0/10 * * * * *  每10秒 一次
                    //2.2 合法性校验.

                    // cron ="0 0/5 * * * ?";
//                        cron ="0 0/5 * * * ?";
                    try {
                      cron =   "0/10 * * * * *";  //每10秒 一次
//                            cron = "0 00 08 * *  ?";

                        System.out.println("小凤微信推送！时间为"+cron);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

//                    cron = "0 00 07 * *  ?";
//                        cron = "0/10 * * * * *";

                    //2.3 返回执行周期(Date)
                    return new CronTrigger(cron).nextExecutionTime(triggerContext);
                }
        );
    }
}
